function loadRomScript(fileName) {
    var rom = getItem('fmj/games/rom');

    // 检查是否成功读取到值
    if (!rom) {
        console.error("No ROM value found in localStorage for key 'fmj/games/rom'.");
        return;
    }

    insertScript('../games/' + rom + '/' + fileName);
}

function insertScript(src, isBody) {
    var script = document.createElement('script');
    script.src = src;
    script.type = 'text/javascript'; 
    isBody
        ? document.body.appendChild(script)
        : document.head.appendChild(script);

}

function getItem(key) {
    // 检查 localStorage 是否可用
    if (typeof(Storage) === "undefined") {
        console.error("localStorage is not supported in this browser.");
        return;
    }
    return localStorage.getItem(key);
}

function main() {
    var title = getItem('fmj/games/name');
    if (title) {
        window.document.title = title;
    }
}

main();
// insertScript('../js/jquery.min.js');
// insertScript('../js/encoding-indexes.js');
// insertScript('../js/encoding.js');
// insertScript('../js/sys.js');
// insertScript('../js/kotlin.js');
// insertScript('../js/font.js');
loadRomScript('rom.js');
insertScript('../js/fmj.core.js');